package com.hp.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.jasper.tagplugins.jstl.core.If;

@WebServlet("/LoginServlet")
public class LoginServlet extends HttpServlet {
	UserDao dao=new UserDao();
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(request, response);
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		request.setCharacterEncoding("utf-8");
		String name = request.getParameter("name");
		String pwd = request.getParameter("pwd");
		String sex = request.getParameter("sex");
		
		String[] hobbys=request.getParameterValues("hobby");
		String hobbyStr ="";
		if (hobbys !=null) {
			for(String hobby: hobbys) {
				hobbyStr += hobby+",";
			}
			hobbyStr=hobbyStr.substring(0, hobbyStr.length()-1);
		}
		System.out.println("name:"+name);
		System.out.println("pwd:"+pwd);
		
		User ue=new User(name, pwd);
		boolean flag=dao.inserUser(ue);
		
		request.setAttribute("result",flag );
		request.getRequestDispatcher("result.jsp").forward(request, response);
		
	}
	
}
